<?php
declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\UpdateBasicUserInfoValidate;
use App\Http\Requests\UpdateUserInfoValidate;
use App\Library\Response;
use App\Logic\User\Service\AuthorFansService;
use App\Logic\User\Service\ImageCollectionService;
use App\Logic\User\Service\ImageShareService;
use App\Logic\User\Service\UserService;
use Illuminate\Http\JsonResponse;
use RedisException;

class UserController extends Controller
{
    public function info(): JsonResponse
    {
        return Response::success((new UserService())->serviceUserInfo());
    }

    public function update(UpdateUserInfoValidate $validate): JsonResponse
    {
        $updateUserInfo = (new UserService())->serviceUpdate($validate->all());
        if ($updateUserInfo["row"] > 0) {
            return Response::success($updateUserInfo);
        }
        return Response::error();
    }

    public function score(): JsonResponse
    {
        return Response::success((new UserService())->serviceScore());
    }

    /**
     * 用户中心汇总数据
     * @return JsonResponse
     */
    public function overview(): JsonResponse
    {
        return Response::success((new UserService())->serviceOverview());
    }

    /**
     * 分享列表
     * @return JsonResponse
     */
    public function share(): JsonResponse
    {
        return Response::success((new ImageShareService())->serviceSelect(request()->all()));
    }

    /**
     * 收藏列表
     * @return JsonResponse
     */
    public function collection(): JsonResponse
    {
        return Response::success((new ImageCollectionService())->serviceSelect(request()->all()));
    }

    /**
     * 关注列表
     * @return JsonResponse
     */
    public function attention(): JsonResponse
    {
        return Response::success((new AuthorFansService())->serviceSelect(request()->all()));
    }
}
